package com.pg.service.impl;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pg.entity.sy.EipLightningImpulse;
import com.pg.mapper.EipLightningImpulseMapper;
import com.pg.service.EipLightningImpulseService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 雷电冲击试验 服务实现类
 * </p>
 *
 * @Author likl
 * @since 2020-06-07
 */
@Service
@DS("proxyDs")
@Primary
public class EipLightningImpulseServiceImpl extends ServiceImpl<EipLightningImpulseMapper, EipLightningImpulse> implements EipLightningImpulseService {

    @Autowired
    private EipLightningImpulseMapper eipLightningImpulseMapper;

    @Override
    public IPage<EipLightningImpulse> selectForList(Page<EipLightningImpulse> page, EipLightningImpulse eipLightningImpulse, Date startCheckTime, Date endCheckTime) {
        LambdaQueryWrapper<EipLightningImpulse> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(eipLightningImpulse.getSupplierWorkNo())) {
            queryWrapper.like(EipLightningImpulse::getSupplierWorkNo, eipLightningImpulse.getSupplierWorkNo());
        }
        if (StringUtils.isNotEmpty(eipLightningImpulse.getCategoryType())) {
            queryWrapper.like(EipLightningImpulse::getCategoryType, eipLightningImpulse.getCategoryType());
        }
        if (StringUtils.isNotEmpty(eipLightningImpulse.getProductModel())) {
            queryWrapper.like(EipLightningImpulse::getProductModel, eipLightningImpulse.getProductModel());
        }
        if (StringUtils.isNotEmpty(eipLightningImpulse.getEquipmentName())) {
            queryWrapper.like(EipLightningImpulse::getEquipmentName, eipLightningImpulse.getEquipmentName());
        }
        if (StringUtils.isNotEmpty(eipLightningImpulse.getPdCode())) {
            queryWrapper.like(EipLightningImpulse::getPdCode, eipLightningImpulse.getPdCode());
        }
        if (startCheckTime != null) {
            queryWrapper.ge(EipLightningImpulse::getCheckTime, startCheckTime);
        }
        if (endCheckTime != null) {
            queryWrapper.le(EipLightningImpulse::getCheckTime, endCheckTime);
        }
        return eipLightningImpulseMapper.selectPage(page, queryWrapper);
    }
}
